package com.bijiawang.user.controller;

import com.ramostear.captcha.HappyCaptcha;
import com.ramostear.captcha.support.CaptchaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class CaptchaController {
    @GetMapping("/captcha/{qq}")
    public void happyCaptcha(HttpServletRequest request, HttpServletResponse response){
        HappyCaptcha.require(request,response).height(33).width(122).type(CaptchaType.NUMBER).build().finish();
    }

    @ResponseBody
    @GetMapping("/verify")
    public String verify(@RequestParam("code") String code, HttpServletRequest request){
        boolean flag = HappyCaptcha.verification(request,code,true);
        if(flag){
            return "true";
        }else {
            return "false";
        }
    }

    @GetMapping("/changeInfo")
    public String changeInfo(){
        return "changeInfo";
    }

}
